# -*- coding: UTF-8 -*-
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from time import sleep
from selenium.webdriver.chrome.options import Options
from chinese_calendar import is_workday
import time

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--remote-debugging-port=9222')

path = Service('/app/chromedriver')
hcm = 'http://quote.eastmoney.com/qihuo/hcm.html'
ren = 'https://stage.irendui.com/v1/jec/rendui/bigDishPrice/batchSubmitPrice'

driver = webdriver.Chrome(service = path,options = chrome_options)
driver.get(hcm)
T=1
lst=-1
log=open('syncData.log','w')
while True:
    price = int(driver.find_element(By.CLASS_NAME, 'zxj').text)
    datetime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
    if price==lst:
    	sleep(T)
    	lst=price
    	continue
    log.write(str(price)+'和因此'+datetime+'\n')
    response = requests.post(
        ren,
        headers={
            'userId': '123456'
        }, json=[{
            'price': price,
            'categoryId': '154535254058395648',
            'category': '大盘价',
            'siteId': '149998345556649984',
            'dateTime': datetime
        }])
    lst=price
    sleep(T)


